package com.tyqx.hashchainbiz.controller;

import com.tyqx.hashchainbean.vo.ImageQueryParamVO;
import com.tyqx.hashchainbean.vo.ImageVO;
import hashchainutil.common.Dto;
import hashchainutil.common.DtoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/image")
@CrossOrigin
public class ImageFileController {

    @Autowired
    private MongoTemplate mongoTemplate;

    @RequestMapping(value = "/getFile", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public Dto getDonateCashByTime(@RequestBody ImageQueryParamVO imageQueryParamVO) throws Exception {
        String attachmentHashValue = imageQueryParamVO.getAttachmentHashValue();
        Criteria criteria = Criteria.where("hashValue").is(attachmentHashValue);
        Query query = Query.query(criteria);
        List<ImageVO> imageVO = mongoTemplate.find(query, ImageVO.class, imageQueryParamVO.getCollectionName());
        return DtoUtil.returnSuccess("获取图片成功",imageVO);
    }
}
